﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Data;
using DataProvider;

namespace SGBDSecurity
{
    public partial class AlterTable : Form
    {
        User aUser;
        UserDataProvider aUserDataProvider;


        public AlterTable(User iUser)
        {
            aUser = iUser;
            aUserDataProvider = new UserDataProvider();
            InitializeComponent();
            this.lNome.Text = iUser.Login;
            this.lNivel.Text = iUser.Classe + "";

            List<Table> aList = aUserDataProvider.GetUserViewTableAlter(iUser);

           dataGridView1.DataSource = aList;

        }

        private void btnChangeFields_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                Table aTable = new Table();
                aTable.STable = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                aTable.STipoSeguranca = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                if (aTable.STipoSeguranca.Equals("tabela"))
                {
                    aTable.Classe = int.Parse(dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
                }
                InsertRow view = new InsertRow(aUser, aTable);
                view.Visible = true;
            }   
        }

        private void btnChangeReg_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                Table aTable = new Table();
                aTable.STable = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                aTable.STipoSeguranca = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                if (aTable.STipoSeguranca.Equals("tabela"))
                {
                    aTable.Classe = int.Parse(dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
                }
                ModifyRows view = new ModifyRows(aUser, aTable);
                view.Visible = true;
            } 

        }

        private void btnRemoveTable_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                Table aTable = new Table();
                aTable.STable = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                aTable.STipoSeguranca = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                if (aTable.STipoSeguranca.Equals("tabela"))
                {
                    aTable.Classe = int.Parse(dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
                }
                DeleteRow view = new DeleteRow(aUser, aTable);
                view.Visible = true;
            } 
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        } 
  
    }
}
